#include "Interpolation.h"
#include<fstream>
#define pi acos(-1)

class F2:public Function
{
   public:
           double operator()(const double &x)const
           {
               return 1/(1+25*pow(x,2));
           }
};

class G2:public Function
{
   private:
           int n;
   public:
           G2(int n):n(n){}
           double operator()(const double &x)const
           {
               return cos((2*x+1)*pi/(2*n));
           }
           double diff(const int &order,const double &x)const
           {
               return 0;
           }
};

int main()
{
     G2 g1(5),g2(10),g3(15),g4(20);
     F2 f;
     double non;
     double out1[49];
     double out2[49];
     Subroutine Sub1(f,g1,4),Sub2(f,g2,9),Sub3(f,g3,14),Sub4(f,g4,19);
     Sub1.generate();
     Sub2.generate();
     Sub3.generate();
     Sub4.generate();
     non=Sub1.Newtvalue(0.5);
     non=Sub2.Newtvalue(0.5);
     non=Sub3.Newtvalue(0.5);
     non=Sub4.Newtvalue(0.5);

     for(int i=0;i<=4;i++)
     {
         cout<<g1(double(i))<<"  "<<Sub1.c[i]<<" "<<endl;
         out1[i]=Sub1.c[i];
         out2[i]=g1(double(i));
     }  
     cout<<endl;
     for(int i=0;i<=9;i++)
     {
         cout<<g2(double(i))<<"  "<<Sub2.c[i]<<" "<<endl;
         out1[i+5]=Sub2.c[i];
         out2[i+5]=g2(double(i));
     }  
     cout<<endl;
     for(int i=0;i<=14;i++)
     {
         cout<<g3(double(i))<<"  "<<Sub3.c[i]<<" "<<endl;
         out1[i+15]=Sub3.c[i];
         out2[i+15]=g3(double(i));
     }  
     cout<<endl;
     for(int i=0;i<=19;i++)
     {
         cout<<g4(double(i))<<"  "<<Sub4.c[i]<<" "<<endl;
         out1[i+30]=Sub4.c[i];
         out2[i+30]=g4(double(i));
     }  
     
     ofstream datafile;
     datafile.open("2.txt",ofstream::app);
     for(int i=0;i<=49;i++)
     {
         datafile<<out1[i]<<" "<<out2[i]<<endl;
     }
     datafile.close();
     
     return 0;
}
